import JWT from 'jsonwebtoken';
import {PrismaClient} from '@prisma/client';


const client = new PrismaClient();
// 30 seconds
// const validDuration = 30;
const jwtKey = '123456';

type jwtPayload = {
  aud: string
}

type requestHead = {
  timestamp: number,
  apiVersion: string
}

enum accountType {
  'cash' = 1,
  'card', 'epay'
}

enum billType {
  'income' = 0,
  'food', 'drink', 'transportation',
  'shopping', 'entertainment', 'housing',
  'electronics', 'medical', 'misc'
}

const billTypeCounts = 10;


function signJWT(payload: jwtPayload, secretKey = jwtKey) {
  return JWT.sign(payload, secretKey, {
    expiresIn: '1h',
  });
}

// function validChecker(reqBody: requestHead) {
//   const now = new Date().getTime();
//   if(now - reqBody.timestamp > validDuration) {
//     return false;
//   }
//   if(reqBody.apiVersion !== 'v1.0') {
//     return false;
//   }
//   return true;
// }

export {
  accountType, billType, jwtPayload, requestHead,
  billTypeCounts,
  signJWT,
  client
};